package com.sxt.sys.service.impl;

import com.sxt.sys.domain.User;
import com.sxt.sys.mapper.UserMapper;
import com.sxt.sys.service.UserService;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.vo.UserVo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 阿刘
 * @since 2019-04-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
	@Autowired
	private UserMapper userMapper;
	@Override
	public DataGridView queryAllUser(UserVo userVo) {
		IPage<User> page=new Page<>(userVo.getPage(),userVo.getLimit());
		QueryWrapper<User> queryWrapper=new QueryWrapper<>();
		if(null!=userVo.getName()) {
			queryWrapper.like("name", userVo.getName());
		}
		if(null!=userVo.getAddress()) {
			queryWrapper.like("address", userVo.getAddress());
		}
		this.userMapper.selectPage(page,queryWrapper);
		return new DataGridView(page.getTotal(),page.getRecords());
	}
	@Override
	public void addDept(UserVo userVo) {
		this.userMapper.insert(userVo);
	}
	@Override
	public void updateUser(UserVo userVo) {
		this.userMapper.updateById(userVo);
	}
	@Override
	public void deleteUser(UserVo userVo) {
		this.userMapper.deleteById(userVo);
	}
	
}
